package com.szdtoo.controller;


import com.szdtoo.annotation.SystemLog;
import com.szdtoo.domain.User;
import com.szdtoo.response.Result;
import com.szdtoo.service.OrganizationService;
import com.szdtoo.service.RoleService;
import com.szdtoo.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private OrganizationService organizationService;

    @SystemLog("查看用户")
    @RequiresPermissions("user:view")
    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public Result userList() {
        Map<String,Object> map = new HashMap<>();
        map.put("userList",userService.findAll());
        return Result.success("操作成功",map);
    }

    @RequiresPermissions("user:create")
    @RequestMapping(value = "skipToUserEdit", method = RequestMethod.GET)
    public String skipToUserEdit(HttpServletRequest request) {
        request.setAttribute("organizationList", organizationService.findAll());
        request.setAttribute("roleList", roleService.findAll());
        request.setAttribute("user", new User());
        request.setAttribute("op","新增");
        return "user/userEidt";
    }
}
